using System.Collections.Generic;
using System.Windows.Forms;

namespace Mistral.ComponentModel
{
	public class ListBoxEditorMultiple : ListBoxEditor
	{
		public override Control CreateEditorControl( ItemViewDelegate viewDelegate )
		{
			_viewDelegate = viewDelegate;
			_listBox = new ListBox();
			_listBox.BorderStyle = BorderStyle.None;
			_listBox.SelectionMode = SelectionMode.MultiExtended;		
			return _listBox;
		}

		public override object SelectedItem
		{
			get
			{
				List<object> items = new List<object>( );
				foreach ( object selectedItem in _listBox.SelectedItems )
				{
					object view = GetItemByView( selectedItem );
					if( view != null )
						items.Add( view );
				}
				return items.ToArray();
			}
			set
			{
				if( value is object[] )
				{
					object[] objects = value as object[];
					foreach ( object obj in objects )
					{
						_listBox.SelectedItems.Add( GetItemView(obj) );
					}
				}
				else
				{
					_listBox.SelectedItem = value;
				}
			}
		}

	}
}